use swc_core::ecma::ast::*;

pub fn get_mounted_stmt(module: &Module) -> Option<Stmt> {
    module.body.iter().find_map(|item| {
        if let ModuleItem::Stmt(stmt) = item {
            if let Stmt::Expr(expr_stmt) = stmt {
                if let Expr::Call(call_expr) = &*expr_stmt.expr {
                    // 使用 &* 来解引用 Box 并获取内部的引用
                    if let Callee::Expr(callee_expr) = &call_expr.callee {
                        if let Expr::Ident(ident) = &**callee_expr {
                            if ident.sym == "onMounted" {
                                return Some(stmt.clone());
                            }
                        }
                    }
                }
            }
        }
        None
    })
}
pub fn transform(module: &Module) -> Result<(), std::io::Error> {
    println!("{:?}", module.span);

    println!("body item长度:{}", module.body.len());
    for body_item in module.body.iter() {
        println!("{:?}\n", body_item);
    }

    Ok(())
}
